import { post, get, request } from '@/utils/request'
import { cloneObj } from '@/utils/data'
import { getToken, encrypt, getAt } from '@/utils/auth'
import settigns from '@/settings'
import { EpMessage as Message } from 'ep-ui'

let { tokenName } = settigns

/**
 * 登录
 * @param {*} data
 */
export function login(data) {
  data = cloneObj(data)
  let ciphertext = data.password ? encrypt(data.password, EPENV.encrypted) : ''
  data.password = ciphertext
  // return request({
  //   method: 'POST',
  //   dataType: 'json',
  //   url: '/hunterAuth/login',
  //   data: data,
  //   headerSign: false,
  //   headers: {
  //     'Hunter-User-Origin': 'hunterToken'
  //   }
  // })
  let res = {
    data:{
      flag: 'T',
      errorCode: null,
      errorInfo: null,
      sign: '',
      data: {
        hunterToken: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTG9naW5JZCI6Ind0bHUiLCJzdWIiOiJ3dGx1IiwidXNlck5hbWUiOiLpmYblkLTmtpsiLCJleHAiOjE3MDA4MjcyNjcsImlhdCI6MTcwMDc0MDg2N30.xGpSJ0ckO8HRB5kof9wtPt_nqa_kzQeYFTLWCAraICc'
      }
    }
  }
  return new Promise((resolve, reject) => {
    resolve(res)
  })
}

/**
 * 登录
 * @param {*} data
 */
export function logout() {
  return request({
    method: 'GET',
    dataType: 'json',
    url: '/hunterAuth/userLogout',
    headerSign: false
  })
}

/**
 * register
 * @param {*} data
 */
export function register(data) {
  data = cloneObj(data)
  let ciphertext = data.password ? encrypt(data.password, EPENV.encrypted) : ''
  data.password = ciphertext
  return request({
    method: 'POST',
    dataType: 'json',
    url: '/hunterAuth/register',
    data: data,
    headerSign: false
  })
}

/**
 * 获取用户信息
 */
export function getUserInfo() {
  // return get({
  //   url: '/hbAuthSchemaEpma/getHunterUserInfo',
  //   // params: {
  //   //   refresh_token: getToken()
  //   // }
  // })

  let res= {
    data: {
      flag: 'T',
      errorCode: null,
      errorInfo: null,
      sign: '',
      data: {
        userName: '陆吴涛',
        userLoginId: 'wtlu',
        admin: true
      }
    }
  }
  return new Promise((resolve, reject) => {
    resolve(res)
  })
}
